//
//  UIViewController+AddTableViewHeaderFooter.m
//  即时通讯
//
//  Created by huangtao on 16/7/9.
//  Copyright © 2016年 fish. All rights reserved.
//

#import "UIViewController+AddTableViewHeaderFooter.h"

@implementation UIViewController (AddTableViewHeaderFooter)

//添加下拉刷新
- (void)addRefreshHeader:(UITableView *)tableView
{
    tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(pullRefreshing)];
}
//添加上拉刷新
- (void)addRefreshFooter:(UITableView *)tableView
{
    tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(pushRefreshing)];
}

//下拉刷新
- (void)pullRefreshing
{
    
}
//上拉刷新
- (void)pushRefreshing
{
    
}

#pragma mark- NSNotification

- (void)removeAllObservers
{
    [NotificationCenter removeObserver:self];
}


#pragma mark- Cancle
- (void)addCancelBarButtonItem:(BOOL)force {
    if (self.navigationItem.leftBarButtonItem && force == NO) {
        return;
    }
        UIImage *image = [UIImage imageNamed:@"cancel"];
        UIImage *selectedImage = [UIImage imageNamed:@"cancel_selected"];
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(0, 0, image.size.width, image.size.height);
        [button setImage:image forState:UIControlStateNormal];
        [button setImage:selectedImage forState:UIControlStateHighlighted];
        [button addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.leftBarButtonItem =  [[UIBarButtonItem alloc] initWithCustomView:button];
}

- (void)cancel:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end





